//
//  AccountCancellationVC.m
//  CreditHub
//
//  Created by chenglang on 2024/9/21.
//

#import "AccountCancellationVC.h"
#import "PersonalCenterItemView.h"
#import "HomeRequest.h"
#import "BankPopupViewController.h"

@interface AccountCancellationVC ()
@property (weak, nonatomic) IBOutlet UIView *contentView;
@property (weak, nonatomic) IBOutlet UIImageView *imageTitle;
@property (weak, nonatomic) IBOutlet UILabel *labelTitle;
@property (weak, nonatomic) IBOutlet UILabel *labelDetail;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutHeight;
@property (nonatomic , strong) NSMutableArray *arraySuchan;
@property (weak, nonatomic) IBOutlet UIButton *buttonSelect;

@end

@implementation AccountCancellationVC

- (void)viewDidLoad {
    [super viewDidLoad];

    self.ch_title = @"Settings";
    
    self.layoutHeight.constant = SCREEN_WIDTH-30;
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSDictionary *dicUserInfo = [defaults objectForKey:@"AccountCancellation"];
    if([dicUserInfo isKindOfClass:[NSDictionary class]] &&dicUserInfo.count > 0){
        self.labelTitle.text = dicUserInfo[@"outside"];
        self.labelDetail.text = dicUserInfo[@"grown"];
        [self.buttonSelect setTitle:[NSString stringWithFormat:@" %@",dicUserInfo[@"trust"]] forState:UIControlStateNormal];
    }
   
}
- (IBAction)clickAccount:(id)sender {
    
    if(!self.buttonSelect.selected){
        xhl_showMessage(@"Please read and agree to the cancellation agreement！");
        return;
    }
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Are you sure to cancel your account?" message:@"" preferredStyle:UIAlertControllerStyleAlert];
    __weak typeof(self) weakSelf = self;
    UIAlertAction *goToSettingsAction = [UIAlertAction actionWithTitle:@"Confirm" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
       
        [weakSelf requestAccount];
       
        
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancle" style:UIAlertActionStyleCancel handler:nil];
    [alertController addAction:goToSettingsAction];
    [alertController addAction:cancelAction];
    [self presentViewController:alertController animated:YES completion:nil];
    
//
}

- (IBAction)clickAgree:(id)sender {
    
    self.buttonSelect.selected = !self.buttonSelect.selected;
}

- (void)requestAccount{
    xhl_hudLoading();
    __weak typeof(self) weakSelf = self;
    [HomeRequest requestAccountCancellationSuccess:^(NSURLSessionDataTask *task, id response) {
        if([response[@"ofexcitement"] integerValue] == 0){
            [UserInfoModel logout];
            [weakSelf.navigationController popToRootViewControllerAnimated:YES];
        }
        xhl_showMessage(response[@"shared"]);
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        xhl_hudLoading();
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
